package cn.falcon.fmobi.console.requestparam;

import cn.falcon.fmobi.dao.po.TargetInfo;
import cn.falcon.fmobi.dao.util.DataUtils;
import cn.falcon.marketing.api.response.Data;
import com.alibaba.druid.support.json.JSONUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * User: shirongkang
 * Date: 2017/9/21
 * Time: 19:27
 * Desc:定向包
 */
public class TargetPackageParam {

    private Integer id;

    /**
     * 广告主ID
     */
    private Integer advertiserId;

    /**
     * 投放广告类型 1 展示广告  2 微信朋友圈
     */
    private Integer adType;

    /**
     * 定向包名称
     */
    private String name;

    /**
     * 定向描述
     */
    private String description;

    /**
     * 定向数据
     */
//    @JsonProperty("target_param")
    private TargetParam targetParam;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAdvertiserId() {
        return advertiserId;
    }

    public void setAdvertiserId(Integer advertiserId) {
        this.advertiserId = advertiserId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public TargetParam getTargetParam() {
        return targetParam;
    }

    public void setTargetParam(TargetParam targetParam) {
        this.targetParam = targetParam;
    }

    public Integer getAdType() {
        return adType;
    }

    public void setAdType(Integer adType) {
        this.adType = adType;
    }

    public TargetInfo getTargetInfo() {
        TargetInfo targetInfo = new TargetInfo();
        targetInfo.setId(null == this.getId() ? 0 :this.getId());
        targetInfo.setAdvertiserId(this.getAdvertiserId());
        targetInfo.setName(this.getName());
        targetInfo.setDescription(this.getDescription());
        targetInfo.setAge(this.getTargetParam().getAge());
        targetInfo.setAdType(this.getAdType());
        if (null != this.getTargetParam().getBehavior()) {
            targetInfo.setAppBehavior(DataUtils.toJSONString(this.getTargetParam().getBehavior()));
        }else {
            targetInfo.setAppBehavior("");
        }
        if (null != this.getTargetParam().getCustomAudience()) {
            targetInfo.setCustomAudience(StringUtils.join(this.getTargetParam().getCustomAudience(), ","));
        }else {
            targetInfo.setCustomAudience("");
        }
        if (null != this.getTargetParam().getEducation()) {
            targetInfo.setEducation(StringUtils.join(this.getTargetParam().getEducation(), ","));
        }else {
            targetInfo.setEducation("");
        }
        if (null != this.getTargetParam().getGender()) {
            targetInfo.setGender(StringUtils.join(this.getTargetParam().getGender(), ","));
        }else {
            targetInfo.setGender("");
        }
        if (null != this.getTargetParam().getMarriage()) {
            targetInfo.setRelationshipStatus(StringUtils.join(this.getTargetParam().getMarriage(), ","));
        }else {
            targetInfo.setRelationshipStatus("");
        }
        if (null != this.getTargetParam().getArea()) {
            targetInfo.setGeoLocation(DataUtils.toJSONString(this.getTargetParam().getArea()));
        }else {
            targetInfo.setGeoLocation("");
        }
        targetInfo.setKeyword(DataUtils.isNull(this.getTargetParam().getKeyword())? "" : this.getTargetParam().getKeyword());
        if (null != this.getTargetParam().getTelcom()) {
            targetInfo.setNetworkOperator(StringUtils.join(this.getTargetParam().getTelcom(), ","));
        }else {
            targetInfo.setNetworkOperator("");
        }
        if (null != this.getTargetParam().getConnection()) {
            targetInfo.setNetworkType(StringUtils.join(this.getTargetParam().getConnection(), ","));
        }else {
            targetInfo.setNetworkType("");
        }
        if (null != this.getTargetParam().getHours()) {
            targetInfo.setTimeWindow(DataUtils.toJSONString(this.getTargetParam().getHours()));
        }else {
            targetInfo.setTimeWindow("");
        }
        if (null != this.getTargetParam().getOs()) {
            targetInfo.setUserOs(StringUtils.join(this.getTargetParam().getOs(), ","));
        }else {
            targetInfo.setUserOs("");
        }
        if (!DataUtils.isNull(this.getTargetParam().getInterests())) {
            targetInfo.setBusinessInterest(StringUtils.join(this.getTargetParam().getInterests(), ","));
        }else {
            targetInfo.setBusinessInterest("");
        }
        return targetInfo;
    }


}
